package com.dw.widget.slideshow.config.view.list;

import java.util.EventListener;

import com.dw.widget.slideshow.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

public class ListBigIconSelectView extends BaseListItemView {

	private ImageView iconView;
	private TextView textView;
	private CheckBox cbSelect;
	
	private OnCheckBoxSwitchListener cbListener;
	
	public ListBigIconSelectView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
	}

	public ListBigIconSelectView(Context context, AttributeSet attrs) {
		this(context, attrs, -1);
	}
	
	public ListBigIconSelectView(Context context) {
		this(context, null);
	}

	@Override
	protected void onFinishInflate() {

		super.onFinishInflate();
		//LayoutInflater.from(getContext()).inflate(R.layout.listitem_bigiconselect, this, true);
		
		iconView = (ImageView)findViewById(R.id.listitembigiconselect_image);
		textView = (TextView)findViewById(R.id.listitembigiconselect_text);
		cbSelect = (CheckBox)findViewById(R.id.listitembigiconselect_cb);
		
		// 整行选择事件
		cbSelect.setFocusable(false);
		cbSelect.setClickable(false);
		
		this.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				if(cbListener != null)
				{
					cbListener.OnSwitch();
				}
			}
		});
	}
	
	public void setIcon(int res)
	{
		if(res < 0)
		{
			return;
		}
		
		iconView.setImageResource(res);
	}
	
	public void setText(String text)
	{
		if(text == null)
		{
			return;
		}
		
		textView.setText(text);
	}
	
	public CheckBox getCheckBox()
	{
		return cbSelect;
	}
	
	public void setOncheckBoxSwitchListener(OnCheckBoxSwitchListener listener)
	{
		cbListener = listener;
	}
	
	public interface OnCheckBoxSwitchListener extends EventListener
	{
		abstract public void OnSwitch();
	}
}
